package com.qd.flow.manager;

import com.qd.flow.listener.FlowListener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 〈一句话功能简述〉<br>
 *
 * @author sjk
 * @create 2023-12-21 15:56
 * @since 1.0.0
 */
@Component
@Slf4j
public class FlowListenerLocator implements ApplicationContextAware {

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        Map<String, FlowListener> beans = applicationContext.getBeansOfType(FlowListener.class);
        log.info("实现了流程引擎监听接口的数量： {}", beans.size());
        if (!beans.isEmpty()) {
            beans.forEach((key, flowListener) -> {
                log.info("流程引擎监听接口resource: {}", flowListener.getClass());
                FlowListenerManager.getInstance().saveFlowListener(flowListener);
            });
        }
    }
}